using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Trigits
{
    public class PassButton
    {
        private bool enabled = false;
        private bool clicked = false;
        private bool newClick = true;
        
        private Texture2D clickedBackground;
        private Texture2D enabledBackground;
        private Texture2D disabledBackground;

        private Rectangle bounds;

        public PassButton(
            Texture2D clickedBackground,
            Texture2D enabledBackground,
            Texture2D disabledBackground,
            Rectangle bounds)
        {
            this.clickedBackground = clickedBackground;
            this.enabledBackground = enabledBackground;
            this.disabledBackground = disabledBackground;
            this.bounds = bounds;
        }

        public bool inBounds(Vector2 v)
        {
            if (v.X >= bounds.X && v.X <= bounds.X + bounds.Width &&
                v.Y >= bounds.Y && v.Y <= bounds.Y + bounds.Height)
                return true;
            return false;
        }

        public bool Click()
        {
            if (enabled)
            {
                clicked = true;

                if (newClick)
                {
                    newClick = false;
                    return true;
                }
            }

            return false;
        }

        public bool isEnabled(bool enabled)
        {
            this.enabled = enabled;
            return enabled;
        }

        public bool isEnabled()
        {
            return enabled;
        }

        public void setBounds(Rectangle bounds)
        {
            this.bounds = bounds;
        }

        public void Draw(GraphicsDevice graphics, SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            
            if(enabled && clicked)
                spriteBatch.Draw(clickedBackground, bounds, Color.White);
            if(enabled)
                spriteBatch.Draw(enabledBackground, bounds, Color.White);
            if(!enabled)
                spriteBatch.Draw(disabledBackground, bounds, Color.White);
            spriteBatch.End();
        }
    }
}
